﻿/*
 * Created by SharpDevelop.
 * User: Intel
 * Date: 11.12.2014
 * Time: 14:31
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Linq;
namespace Invent
{
  /// <summary>
  /// Description of EmployeeEdit.
  /// </summary>

  public partial class EmployeeEdit : Form
  {
    DatabaseInvent m_db;
    Guid m_EmployeeUID;
    bool m_new = false;
    DataRow getRow(){ return (from d in m_db.Employee.AsEnumerable() where d.Field<Guid>("EmployeeUID")==m_EmployeeUID select d).Single();}
    public EmployeeEdit(DatabaseInvent db,Guid EmployeeUID)
    {
      m_db = db;
			m_EmployeeUID = EmployeeUID;
			if (m_EmployeeUID == Guid.Empty)
			{
			  DataRow row = m_db.newEmployee("Ф.И.О.");
			  m_EmployeeUID = row.Field<Guid>("EmployeeUID");
			  m_new = true;
			}
      //
      // The InitializeComponent() call is required for Windows Forms designer support.
      //
      InitializeComponent();
      //ShowSelectors();
      m_db.control_read(this,getRow());
    }
    void Button2Click(object sender, EventArgs e)
    {
      if (m_new)
        m_db.deleteEmployee(m_EmployeeUID);// Удалить если новый не сохранили
      Close();
    }
    void Button1Click(object sender, EventArgs e)
    {
      m_new = false;
      m_db.control_write(this,getRow());
      Close();
    }
    void Button3Click(object sender, EventArgs e)
    {
      m_db.deleteEmployee(m_EmployeeUID);
      Close();
    }
    void EmployeeEditFormClosing(object sender, FormClosingEventArgs e)
    {
      if (m_new)
        m_db.deleteEmployee(m_EmployeeUID);// Удалить если новый не сохранили  
    }
    
  }
}
